import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const $time 	= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '录入人',		name: 'operator_id',			type:'select',		loading:true },
			{ label: '接收时间',		names: ['start_at','end_at'], 	type:'date-range', 	loading:true,	name:'jz-time' },
		],
	}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{				 
			const arr = f.duration['7-0-24']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			this.fetch()		
		})
		$fn.fresh.on( () =>{
			this.fetch()
		}, 'errorRefresh')
	}
	componentWillUnmount(){
		$fn.fresh.remove('errorRefresh')
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 录入人
			$fn.setRow( forms, 'operator_id', await f.getCache({ api:'employee' }) )
			
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'spec-case-info/doubleEntryDiffList', {isIndex:true})
	// 表单
	cols = [
		{ title: '条码号', 		dataIndex: 'code', 		...$fn.table.spec_code },
		{ title: '录入人1', 		dataIndex: 'user1', 	...$fn.table.name },
		{ title: '录入时间1', 	dataIndex: 'time1',  	...$fn.table.time},
		{ title: '录入人2', 		dataIndex: 'user2', 	...$fn.table.name },
		{ title: '录入时间2', 	dataIndex: 'time2',  	...$fn.table.time},
		TableControls.controls.call(this,{ width: 80 }),
	]
	
	// 表格操作按钮
	table_controls = (text,{code}) => {
		const root = '/specimen-manage/info-entry/basicInfo-entry/'
		return [
			Controls.click.call(this, '查看',()=>{
				const {permissions} = $fn.query()
				$fn.pushRoot(this, `${root}double-entry?spec_code=${code}&error=${true}&permissions=${permissions}`)
			}, {ghost:true} ),	// 查看
		]
	}
	
	// 操作按钮
	controls = () => {
		return [
			Controls.back.call(this ),			// 返回
		]
	}
		
	render(){
		return (
			<Page title='双录入纠错'  controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr:'7-0-24'}) }
				{/* 表格 */}
				{ Table.call(this, {isIndex:true}) }
			</Page>
		)
	}
}

export default Index
 // 新增双录入纠错页面 2021-11-3  --马婷 